﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Text;
using WeChatIdentity.Constants;
using WeChatIdentity.Models;

namespace WeChatIdentity.EntityConfigurations
{
    public class UserEntityTypeConfiguration
        : IEntityTypeConfiguration<ApplicationUser>
    {
        public void Configure(EntityTypeBuilder<ApplicationUser> builder)
        {

            builder.ToTable("ApplicationUser", SchemaConstants.SchemaName);

            builder.HasKey(ci => ci.Id);

            builder.Property(ci => ci.Id)
               .IsRequired();

            builder.Property(cb => cb.OpenId)
               .IsRequired(true);
            builder.Property(cb => cb.SubjectId)
               .IsRequired(true);
            builder.Property(cb => cb.NickName)
               .IsRequired(false);
            builder.Property(cb => cb.CreateTime)
               .IsRequired(true);
            builder.Property(cb => cb.UserName)
                .IsRequired(true);
            builder.Property(cb => cb.ConcurrencyStamp)
                .IsRequired(false);
            builder.Property(cb => cb.PasswordHash)
                .IsRequired(false);
            builder.Property(cb => cb.Email)
                .IsRequired(false);

            builder.Property(cb => cb.AvatarUrl)
                .IsRequired(false);
            builder.Property(cb => cb.Gender)
                .IsRequired(false);
            builder.Property(cb => cb.Province)
                .IsRequired(false);
            builder.Property(cb => cb.City)
                .IsRequired(false);
            builder.Property(cb => cb.Country)
                .IsRequired(false);
            //set forekey
            //builder.HasMany(b => b.UserRoles)
            //   .WithOne()
            //   .HasForeignKey("UserId")
            //   .OnDelete(DeleteBehavior.Cascade);

            //builder.HasMany(b => b.UserClaims)
            //    .WithOne()
            //    .HasForeignKey("UserId")
            //    .OnDelete(DeleteBehavior.Cascade);
        }
    }
}
